<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="s"  uri="/struts-tags" %>
<%@ taglib prefix="c"  uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/html">
<head>
   	<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
    <meta http-equiv="X-UA-Compatible" content="chrome=1">
	<title>菜单管理</title>
    <link href="<%=request.getContextPath()%>/css/bootstrap.css" rel="stylesheet" type="text/css">
    <script src="<%=request.getContextPath()%>/js/jquery-2.0.3.min.js" type="text/javascript"></script>
    <script src="<%=request.getContextPath()%>/js/bootstrap.js" type="text/javascript"></script>  
    
        
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/bootstrapValidator.css"/>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/bootstrapValidator.js"></script>
    
    
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/lhdialog/lhgcore.min.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/lhdialog/lhgdialog.js"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/OpenDialog.js"></script>

    <script type="text/javascript">
    
    /* $(document).ready(function() {
    	
    	$('#defaultForm')
        .bootstrapValidator({
            message: 'This value is not valid',
            fields: {
                "t.name": {
                    validators: {
                        notEmpty: {
                            message: '商品系列名称不能为空'
                        }
                    }
                }
            }
        })
    }); */
    
    
  //选择leibiue界面（弹出框）
    function chooseCategory(){
	var flag =1;
	var page = 	"<%=request.getContextPath()%>/category/category_listByPage.action?t1.level=4";
	if(flag == 1){
		var titleText = "";
		PUBLICOBJECT.id = "entid";
		PUBLICOBJECT.title = titleText;
		PUBLICOBJECT.width = "1000";
		PUBLICOBJECT.height = "auto";
		PUBLICOBJECT.titleText = titleText;
		PUBLICOBJECT.page = page;
		var rs = PUBLICOBJECT.openLab();
		rs.ShowDialog();// 打开弹出窗
		var dom = window.frames["lhgfrm_" + PUBLICOBJECT.id];// 弹出框document对象
		rs.addBtn(PUBLICOBJECT.id, "确定", function() {
			var _choose = $(dom.document).find("input[name='idChoose']:checked");//获取到被选择的组织ＩＤ
			var chooseValue = _choose.val();
			if(chooseValue != null){
				rs.cancel();// 关闭当弹出窗
				var chooseName = _choose.siblings("input[name='nameChoose']").val();//获取到被选择的组织名称
				    $("#categoryName").trigger("onchange");//触发productAttrName的onchang事件
			    	$("#categoryId").val(chooseValue);
			    	$("#categoryName").val(chooseName);
			}else{
				alert("请选择一项");
			}
		}, "left");
	
	}
}
  //记录图片框个数
  var picFrameCount = 0;
  
  //选择界面（弹出框）
    function choose(entity){
	  	var flag =1;
	  	var pojo=entity;
	  	var page;
	  	
	  	if(pojo=='brandShow'){
	  	    page = 	"<%=request.getContextPath()%>/brandShow/BrandShow_listByPage.action?params=choose";
      }
	  	if(pojo=='productIntroduction'){
	  	    page = 	"<%=request.getContextPath()%>/product/productIntroduction_listByPage.action?params=choose";
      }
	  	if(pojo=='productPic'){
	  	    page = 	"<%=request.getContextPath()%>/productPic/ProductPic_listByPage.action?params=choose&rows=5";
      }
	  	
	  	
	  	if(flag == 1){
	  		var titleText = "";
	  		PUBLICOBJECT.id = "entid";
	  		PUBLICOBJECT.title = titleText;
	  		PUBLICOBJECT.width = "1000";
	  		PUBLICOBJECT.height = "auto";
	  		PUBLICOBJECT.titleText = titleText;
	  		PUBLICOBJECT.page = page;
	  		var rs = PUBLICOBJECT.openLab();
	  		rs.ShowDialog();// 打开弹出窗
	  		var dom = window.frames["lhgfrm_" + PUBLICOBJECT.id];// 弹出框document对象
	  		rs.addBtn(PUBLICOBJECT.id, "确定", function() {
	  			var _choose = $(dom.document).find("input[name='idChoose']:checked");
	  			var chooseValue = _choose.val();
	  			if(chooseValue != null){
	  				rs.cancel();// 关闭当弹出窗
	  				var chooseName = _choose.siblings("input[name='nameChoose']").val();
	  				
	  				
	  				if(pojo=='brandShow'){
	  					//$("#brandShowName").trigger("onchange");
	  			    	$("#brandShowId").val(chooseValue);
	  			    	$("#brandShowName").val(chooseName);
	  		        }
	  				if(pojo=='productIntroduction'){
	  					//$("#productIntroductionName").trigger("onchange");
	  			    	$("#productIntroductionId").val(chooseValue);
	  			    	$("#productIntroductionName").val(chooseName);
	  		        }
	  				
	  				if(pojo=='productPic'){
	  					//$("#productPicName").trigger("onchange");
	  					$("#choosePicBtnDiv").before('<div id="picFrameDiv'+picFrameCount+'" class="form-group"><label class="col-sm-offset-3 col-sm-2 control-label"></label><div class="col-sm-2"><img id="productPicName'+picFrameCount+
	  							'" style="padding:2px; border:1px solid; margin-bottom:10px;width:200px;height:200px; ">'+
	  							'<input value="'+chooseValue+'" type="hidden" name="productPicIds"'+
	  							'><div class="check" style="color:#a94442;font-size:85%"><span class="checkMsg"></span></div></div>'+
	  							'<div class="col-sm-1"><input class="form-control" type="button" value="删除图片" onclick="deleteChoosePic(\'picFrameDiv'+picFrameCount+'\',this)"></div></div>');
	  			    	$("#productPicId"+picFrameCount).val(chooseValue);
	  			    	$("#productPicName"+picFrameCount).attr("src",chooseName);
	  			    	picFrameCount++;
	  		        }
	  				
	  			}else{
	  				alert("请选择一项");
	  			}
	  		}, "left");
	  	}
  }
    
    var flog=false;
    
	
	  function checkCategoryName(){
		    var productAttrName=$("#categoryName").val();
			productAttrName=productAttrName.trim();
		  if(productAttrName!="" || productAttrName!=null){
			    $("#categoryNameMng").attr("style","color:#3c763d");
	    		$("#categoryName").attr("style","border:1px solid #3c763d");
				$("#msg").text("");
				flog=true;
			}
	  }
//删除已选图片
function deleteChoosePic(id,element){
	$("#"+id).remove();
	element.remove();
}
//添加商品系列
function addProductSeries(){
     $("#defaultForm").attr("action","productSeries/ProductSeries_addProductSeries");
     $("#defaultForm").submit();
}
//修改商品系列
function updateProductSeries(){
     $("#defaultForm").attr("action","productSeries/ProductSeries_updateProductSeries");
     $("#defaultForm").submit();
}
    </script>
</head>
<body>
<div class="panel panel-primary">
  <div class="panel-heading">增加商品系列</div>
  <div class="panel-body">
    
	  <form id="defaultForm" class="form-horizontal" action="" method="post">
	  <input type="hidden" name="t1.category.id" value="${t1.category.id}">
	  <input type="hidden" name="t1.category.name" value="${t1.category.name}">
	     <div class="form-group">
		    <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="categoryNameMng">类别名称：</label>
		    <div class="col-sm-2">
                <input class="form-control" type="text" name="t.category.name" id="categoryName" readonly="readonly" onchange="checkCategoryName()" value="${t.category.name }">
                <input type="hidden" name="t.category.id" id="categoryId" value="${t.category.id}">
		    </div>
		  </div>
	  
		 <div class="form-group">
		    <label for="t.rolename" class="col-sm-offset-3 col-sm-2 control-label">系列名称：</label>
		    <div class="col-sm-2">
		        <input class="form-control" type="text" name="t.name" id="text" placeholder="请输入系列名称" value="${t.name}">
		    </div>
		  </div>
	  	 <div class="form-group">
			 <label class="col-sm-offset-3 col-sm-2 control-label">选择图片：</label>
	     </div>
		  <!-- 修改 -->
		  <c:if test="${!empty method}" >
		  	<c:forEach items="${t.productPicList }" varStatus="status" var="pics" >
		  		<div id="picFrameDivOriginal${status.count }" class="form-group">
		  			<label class="col-sm-offset-3 col-sm-2 control-label"></label>
		  				<div class="col-sm-2">
		  					<img src="${pics.path }" style="padding:2px; border:1px solid; margin-bottom:10px;width:200px;height:200px;">
	  							<input value="${pics.id }" type="hidden" name="productPicIds"><div class="check" style="color:#a94442;font-size:85%"><span class="checkMsg"></span></div></div>
	  							<div class="col-sm-1"><input class="form-control" type="button" value="删除图片" onclick="deleteChoosePic('picFrameDivOriginal${status.count }',this)"></div></div>
		  	</c:forEach>
		  </c:if>
	  	<div id="choosePicBtnDiv" class="form-group">
			 <label class="col-sm-offset-3 col-sm-2 control-label"></label>
		     <div class="col-sm-1">
	               <input class="form-control" type="button" value="选择图片" onclick="choose('productPic')">
		     </div>
		     
	     </div>
	  	<div class="form-group">
		 <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="brandShowNameMng">选择品牌：</label>
		     <div class="col-sm-2">
                <input value="${t.brandShow.name }" class="form-control" type="text" name="t.brandShow.name" id="brandShowName" readonly="readonly" onchange="checkName('brandShowName')">
                <input type="hidden" name="t.brandShow.id" id="brandShowId" value="${t.brandShow.id}">
                <div class="check" style="color:#a94442;font-size:85%"><span class="checkMsg"></span></div>
		     </div>
		     <div class="col-sm-1">
                <input class="form-control" type="button" value="选择品牌" onclick="choose('brandShow')">
		     </div>
	     </div>
	  	<div class="form-group">
		 <label for="" class="col-sm-offset-3 col-sm-2 control-label" id="productIntroductionNameMng">选择详情：</label>
		     <div class="col-sm-2">
                <input class="form-control" type="text" name="t.productIntroduction.name" id="productIntroductionName" readonly="readonly" value="${t.productIntroduction.name }" onchange="checkName('productIntroductionName')">
                <input type="hidden" name="t.productIntroduction.id" id="productIntroductionId" value="${t.productIntroduction.id}">
                <div class="check" style="color:#a94442;font-size:85%"><span class="checkMsg"></span></div>
		     </div>
		     <div class="col-sm-1">
                <input class="form-control" type="button" value="选择详情" onclick="choose('productIntroduction')">
		     </div>
	     </div>

	      <c:if test="${!empty method}" >
	          <input name="method" type="hidden" value="${method }">
			  <input type="hidden" name="t.id" value="${t.id}">
			  <input type="hidden" name="t.creationTime" value="${t.creationTime}">
			  <input type="hidden" name="t.creator" value="${t.creator}">
			  
		  </c:if>
		 
		  <div class="form-group">
		    <div class="col-sm-offset-5 col-sm-7">
		      <input type="button" class="btn btn-default" onclick="<c:if test="${!empty method}" >updateProductSeries()</c:if> <c:if test="${empty method}" >addProductSeries()</c:if>" value="提交">
		      <button type="reset" class="btn btn-default">重置</button>
		    </div>
		  </div>
      </form>
    
  </div>
  
</div>

</body>
</html>
